﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace AgvSystem.Web.Agv_Dispatch
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int Id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(Id);
				}
			}
		}
			
	private void ShowInfo(int Id)
	{
		AgvSystem.BLL.Agv_Dispatch bll=new AgvSystem.BLL.Agv_Dispatch();
		AgvSystem.Model.Agv_Dispatch model=bll.GetModel(Id);
		this.lblId.Text=model.Id.ToString();
		this.txtDispatch_Id.Text=model.Dispatch_Id.ToString();
		this.txtDispatch_Type.Text=model.Dispatch_Type.ToString();
		this.txtTarget_Station_Num.Text=model.Target_Station_Num.ToString();
		this.txtDispatch_Flag.Text=model.Dispatch_Flag.ToString();
		this.txtTransport_Time.Text=model.Transport_Time.ToString();
		this.txtAgv_Num.Text=model.Agv_Num.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtDispatch_Id.Text))
			{
				strErr+="Dispatch_Id格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtDispatch_Type.Text))
			{
				strErr+="Dispatch_Type格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtTarget_Station_Num.Text))
			{
				strErr+="Target_Station_Num格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtDispatch_Flag.Text))
			{
				strErr+="Dispatch_Flag格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtTransport_Time.Text))
			{
				strErr+="Transport_Time格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtAgv_Num.Text))
			{
				strErr+="Agv_Num格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int Id=int.Parse(this.lblId.Text);
			int Dispatch_Id=int.Parse(this.txtDispatch_Id.Text);
			int Dispatch_Type=int.Parse(this.txtDispatch_Type.Text);
			int Target_Station_Num=int.Parse(this.txtTarget_Station_Num.Text);
			int Dispatch_Flag=int.Parse(this.txtDispatch_Flag.Text);
			DateTime Transport_Time=DateTime.Parse(this.txtTransport_Time.Text);
			int Agv_Num=int.Parse(this.txtAgv_Num.Text);


			AgvSystem.Model.Agv_Dispatch model=new AgvSystem.Model.Agv_Dispatch();
			model.Id=Id;
			model.Dispatch_Id=Dispatch_Id;
			model.Dispatch_Type=Dispatch_Type;
			model.Target_Station_Num=Target_Station_Num;
			model.Dispatch_Flag=Dispatch_Flag;
			model.Transport_Time=Transport_Time;
			model.Agv_Num=Agv_Num;

			AgvSystem.BLL.Agv_Dispatch bll=new AgvSystem.BLL.Agv_Dispatch();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
